package com.frxuexi.repair.view

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.View
import com.alibaba.android.arouter.facade.annotation.Autowired
import com.alibaba.android.arouter.facade.annotation.Route
import com.alibaba.android.arouter.launcher.ARouter
import com.blankj.utilcode.util.ToastUtils
import com.frxuexi.lib_base.mvvm.BaseActivity
import com.frxuexi.repair.R
import com.frxuexi.repair.RepairViewModel
import com.frxuexi.repair.databinding.ActivityRepairDetailBinding
import dagger.hilt.android.AndroidEntryPoint

@Route(path = "/repair/RepairDetailActivity")
@AndroidEntryPoint
class RepairDetailActivity : BaseActivity<ActivityRepairDetailBinding, RepairViewModel>() {
    @Autowired
    lateinit var rid: String
    override fun initData() {
        vm.repairByIdData.observe(this) {
            binding.bean = it
            if (it.processingStatus != "已完成") {
                binding.repDetailGroup.visibility = View.VISIBLE
            }
            if (it.processingStatus == "处理中") {
                binding.repDetailProCircle2.setBackgroundResource(com.frxuexi.lib_base.R.drawable.shape_solid_darkgreen)
            }
            if (it.processingStatus == "已完成") {
                binding.repDetailProCircle2.setBackgroundResource(com.frxuexi.lib_base.R.drawable.shape_solid_darkgreen)
                binding.repDetailProCircle3.setBackgroundResource(com.frxuexi.lib_base.R.drawable.shape_solid_darkgreen)
            }
        }

        vm.RepairByIdRoomData.observe(this) {
            binding.bean = it
            if (it.processingStatus != "已完成") {
                binding.repDetailGroup.visibility = View.VISIBLE
            }
            if (it.processingStatus == "处理中") {
                binding.repDetailProCircle2.setBackgroundResource(com.frxuexi.lib_base.R.drawable.shape_solid_darkgreen)
            }
            if (it.processingStatus == "已完成") {
                binding.repDetailProCircle2.setBackgroundResource(com.frxuexi.lib_base.R.drawable.shape_solid_darkgreen)
                binding.repDetailProCircle3.setBackgroundResource(com.frxuexi.lib_base.R.drawable.shape_solid_darkgreen)
            }
        }

        vm.updaterepairData.observe(this) {
            ToastUtils.showLong("完成")
//            finish()
        }

        vm.updateRepairRoomData.observe(this) {
            ToastUtils.showLong("操作完成")
            finish()
        }

    }

    override fun initView() {
        ARouter.getInstance().inject(this)
//        vm.getRepaidById(rid.toInt())
        vm.getRepairByIdRoom(rid.toInt())

        binding.repDetailOk.setOnClickListener {
            if (binding.bean?.processingStatus == "待处理") {
                binding.bean?.processingStatus = "处理中"
                vm.updateRepair(rid.toInt(), binding.bean!!)
                vm.updateRepairRoom(binding.bean!!)
            }
        }

        binding.repDetailRefause.setOnClickListener {
            if (binding.bean?.processingStatus == "处理中") {
                binding.bean?.processingStatus = "已完成"
                vm.updateRepair(rid.toInt(), binding.bean!!)
                vm.updateRepairRoom(binding.bean!!)
            }
        }
    }

}